# Generates online and print versions of SGML source file.

basename	= Book


# SGML source file

sgml_file	= Dsl/$(basename)
openjade_errors	= errors.openjade

gen_dsssl	= Scripts/GenDsssl,102
to_riscos	= Scripts/ToRiscos,102

htmltidy_	= tidy
htmltidyflags	= -f /dev/null -m
htmltidy	= $(htmltidy_) $(htmltidyflags)
openjade_	= openjade
openjadeflags	= -E 1024
openjade	= $(openjade_) $(openjadeflags)
perl		= perl


# Stylesheets

dsl_print	= $(SGML_SHARE)/docbook/docbook/print/director.dsl\#print
dsl_html	= $(SGML_SHARE)/docbook/docbook/html/director.dsl\#html


# Generated files

user_html_file	= UserHTML/index.html
user_htm_file	= UserHTM,faf
user_tex_file	= UserTex,ce5
user_rtf_file	= UserRTF,c32
user_pdf_file	= UserPdf,adf
user_dvi_file	= UserDvi.dvi
user_ps_file	= UserPs
user_text_file	= UserText/index
user_txt_file	= UserTXT

tech_html_file	= TechHTML/index.html
tech_htm_file	= TechHTM,faf
tech_tex_file	= TexhTex,ce5
tech_rtf_file	= TechRTF,c32
tech_pdf_file	= TechPdf,adf
tech_dvi_file	= TechDvi.dvi
tech_ps_file	= TechPs
tech_text_file	= TechText/index
tech_txt_file	= TechTXT


# Build rules

userhtml:	$(user_html_file)
userhtm:	$(user_htm_file)
userrtf:	$(user_rtf_file)
usertext:	$(user_text_file)
usertxt:	$(user_txt_file)
#usertex:	$(user_tex_file)
#userpdf:	$(user_pdf_file)
#userdvi:	$(user_dvi_file)
#userps:	$(user_ps_file)

techhtml:	$(tech_html_file)
techhtm:	$(tech_htm_file)
techrtf:	$(tech_rtf_file)
techtext:	$(tech_text_file)
techtxt:	$(tech_txt_file)
#techtex:	$(tech_tex_file)
#techpdf:	$(tech_pdf_file)
#techdvi:	$(tech_dvi_file)
#techps:	$(tech_ps_file)

html:		userhtml techhtml
htm:		userhtm  techhtm
rtf:		userrtf  techrtf
text:		usertext techtext
txt:		usertxt  techtxt

tech:		techhtml techhtm techrtf techtext techtxt
user:		userhtml userhtm userrtf usertext usertxt

all:		tech user


# Rules for creating directories

techhtmldirs:
	mkdir -p TechHTML/{about,changelog,intro,commands}
	mkdir -p TechHTML/director/{commands,h,s,swis,utils}
	mkdir -p TechHTML/director/menus/{files,system}

techtextdirs:
	mkdir -p TechText/{about,changelog,intro,commands}
	mkdir -p TechText/director/{commands,h,s,swis,utils}
	mkdir -p TechText/director/menus/{files,system}

userhtmldirs:
	mkdir -p UserHTML/{about,changelog,intro,commands}
	mkdir -p UserHTML/director/{commands,swis,utils}
	mkdir -p UserHTML/director/menus/{files,system}

usertextdirs:
	mkdir -p UserText/{about,changelog,intro,commands}
	mkdir -p UserText/director/{commands,swis,utils}
	mkdir -p UserText/director/menus/{files,system}

techdirs:	techhtmldirs techtextdirs
userdirs:	userhtmldirs usertextdirs

dirs:		techdirs userdirs

# Miscellaneous rules

clean:
	rm -rf $(user_html_file) $(user_htm_file) $(user_rtf_file) \
	  $(user_text_file) $(user_txt_file) $(tech_html_file) \
	  $(tech_htm_file) $(tech_rtf_file) $(tech_text_file) \
	  $(tech_txt_file) $(openjade_errors) $(sgml_file) \
	  UserHTML UserText TechHTML TechText

tidy:
	rm -f $(openjade_errors) $(sgml_file)

nosource:
	rm -r Dsl Scripts


# Compile rules

$(user_html_file):	$(gen_dsssl) userhtmldirs
	$(perl) $(gen_dsssl) UserHTML > $(sgml_file)
	cd UserHTML && $(openjade) -t sgml -d $(dsl_html) \
	  ../$(sgml_file) 2> ../$(openjade_errors) || true
	cd UserHTML && for i in `find . -name "*.html"`; \
	  do $(htmltidy) $$i || true; done

$(user_htm_file):	$(gen_dsssl)
	$(perl) $(gen_dsssl) UserHTM > $(sgml_file)
	$(openjade) -t sgml -V nochunks -d $(dsl_html) \
	  $(sgml_file) > $(user_htm_file) 2> $(openjade_errors) || true
	$(htmltidy) $(user_htm_file) || true

$(user_text_file):	$(user_html_file) usertextdirs
	cd UserHTML && for i in `find . -name "*.html"`; \
	  do lynx -force_html -dump $$i | $(perl) ../$(to_riscos) > \
	  ../UserText` echo $$i | cut -d . -f 2`; done

$(user_txt_file):	$(htm_file)
	lynx -force_html -dump $(user_htm_file) | $(perl) $(to_riscos) > \
	  $(user_txt_file)

$(user_rtf_file):	$(gen_dsssl)
	$(perl) $(gen_dsssl) UserHTM > $(sgml_file)
	$(openjade) -t rtf -d $(dsl_print) \
	  $(sgml_file) > $(user_rtf_file) 2> $(openjade_errors) || true
	mv Dsl/$(basename).rtf $(user_rtf_file)


#$(user_tex_file):	$(sgml_file)
#	$(perl) Scripts/GenDSSSL.pl UserHTM > $(sgml_file)
#	$(openjade) -t tex -d $(dsl_print) \
#	  $(sgml_file) > $(user_tex_file) 2> $(openjade_errors) || true
#	mv Dsl/$(basename).tex $(user_tex_file)

## [pdf]jadetex is run 3 times to resolve references.
#$(user_pdf_file):	$(user_tex_file)
#       pdfjadetex $(user_tex_file)
#       pdfjadetex $(user_tex_file)
#       pdfjadetex $(user_tex_file)


$(tech_html_file):	$(gen_dsssl) techhtmldirs
	$(perl) $(gen_dsssl) TechHTML > $(sgml_file)
	cd TechHTML && $(openjade) -t sgml -d $(dsl_html) \
	  ../$(sgml_file) 2> ../$(openjade_errors) || true
	cd TechHTML && for i in `find . -name "*.html"`; \
	  do $(htmltidy) $$i || true; done

$(tech_htm_file):	$(gen_dsssl)
	$(perl) $(gen_dsssl) TechHTM > $(sgml_file)
	$(openjade) -t sgml -V nochunks -d $(dsl_html) \
	  $(sgml_file) > $(tech_htm_file) 2> $(openjade_errors) || true
	$(htmltidy) $(tech_htm_file) || true

$(tech_text_file):	$(tech_html_file) techtextdirs
	cd TechHTML && for i in `find . -name "*.html"`; \
	  do lynx -force_html -dump $$i | $(perl) ../$(to_riscos) > \
	  ../TechText` echo $$i | cut -d . -f 2`; done

$(tech_txt_file):	$(htm_file)
	lynx -force_html -dump $(tech_htm_file) | $(perl) $(to_riscos) > \
	  $(tech_txt_file)

$(tech_rtf_file):	$(gen_dsssl)
	$(perl) $(gen_dsssl) TechHTM > $(sgml_file)
	$(openjade) -t rtf -d $(dsl_print) \
	  $(sgml_file) > $(tech_rtf_file) 2> $(openjade_errors) || true
	mv Dsl/$(basename).rtf $(tech_rtf_file)

#$(tech_tex_file): $(sgml_file)
#	$(perl) Scripts/GenDSSSL.pl TechHTM > $(sgml_file)
#	$(openjade)  $(openjadeflags) -t tex -d $(dsl_print) \
#	  $(sgml_file) > $(tech_tex_file) 2> $(openjade_errors) || true
#	mv Dsl/$(basename).tex $(tech_tex_file)
#
## [pdf]jadetex is run 3 times to resolve references.
#$(tech_pdf_file): $(tech_tex_file)
#       pdfjadetex $(tech_tex_file)
#       pdfjadetex $(tech_tex_file)
#       pdfjadetex $(tech_tex_file)


# This *should* work, but htmldoc has bugs ...
#$(PDF_FILE): $(SGML_FILE)
#       $(OPENJADE) -t sgml -V nochunks -d $(DSL_HTML) \
#       $(SGML_FILE) | htmldoc -f $(PDF_FILE) - \
#	|| true

# Have to use ldp_print to work around htmldoc bugs
# ldp_print can also do the ps file - see script
#$(PDF_FILE): $(HTM_FILE)
#	ldp_print $(HTM_FILE)

#$(DVI_FILE): $(TEX_FILE)
#	jadetex $(TEX_FILE)
#	jadetex $(TEX_FILE)
#	jadetex $(TEX_FILE)

#$(PS_FILE): $(DVI_FILE)
#	dvips $(DVI_FILE)

#$(PS_FILE): $(SGML_FILE)
#       $(OPENJADE) -t sgml -V nochunks -d $(DSL_HTML) \
#       $(SGML_FILE) | htmldoc -f $(PS_FILE) - \
#	|| true



# Where:
#   make
#     generate html (default)
#   make pdf
#     generate just pdf
#   make all
#     generate all files
#   make clean
#     delete all generated files
